<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <div class="icon"
             @click="handleItem(item)"
             v-for="item of page"
             :key="item.id">
          <div class='icon-img'>
            <img class='icon-img-content' :src='item.imgUrl'/>
          </div>
          <div class="text">{{item.desc}}</div>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
  export default {
    name: 'icons',
    props: {
      icons: Array
    },
    computed: {
      pages () {
        let page = []
        this.icons.forEach((bean, index) => {
          let num = Math.floor(index / 8)
          if (!page[num]) {
            page[num] = []
          }
          page[num].push(bean)
        })
        return page
      }
    },
    methods: {
      handleItem (item) {
        alert(item.desc)
      }
    },
    data () {
      return {
        swiperOption: {
          autoplay: false
        }
      }
    }
  }
</script>

<style lang="stylus" type="text/stylus" rel="stylesheet/stylus" scoped>
  @import '~styles/varibles.styl'
  @import '~styles/mixins.styl'
  .icons >>> .swiper-container
    height: 0
    padding-bottom: 50%

    .icon
      position relative
      width 25%
      float left
      height 0
      overflow hidden
      padding-bottom 25%

      .icon-img
        position absolute
        top 0
        bottom 0.22rem
        left 0
        right 0
        padding 0.05rem
        box-sizing border-box

        .icon-img-content
          display block
          margin 0 auto
          height 100%

      .text
        position absolute
        left 0
        right: 0
        bottom 0
        height 0.22rem
        text-align center
        color $darkTextColor
        ellipsis()
        line-height 0.2rem

</style>
